﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Lib.CommonForm;

namespace AUI
{
    public partial class frmDepartmentInfo : FormBase
    {
        int _DepartmentId = 0;
        DataRow m_dr;
        public frmDepartmentInfo(DataRow dr)
        {
            InitializeComponent();
            

            this.txtDepartmentCode.MaxLength = tbl_Department_Length.DepartmentCode;
            this.txtDepartmentName.MaxLength = tbl_Department_Length.DepartmentName;
            this.txtAddress.MaxLength = tbl_Department_Length.Address;
            this.txtEmail.MaxLength = tbl_Department_Length.Email;
            this.txtPhone.MaxLength = tbl_Department_Length.Phone;
            this.txtFax.MaxLength = tbl_Department_Length.Fax;

            _listRole = tbl_RoleRight_Controller.Instance().GetInfo("BoPhan");
            FormGlobals.Control_SetRequired(txtDepartmentCode, txtDepartmentName, cboBranchId);
            LoadComboBox.BranchID_Input(cboBranchId);
            m_dr = dr;
            if (m_dr != null)
            {
                FormGlobals.Panel_FillData(this, dr);
                _DepartmentId = Globals.ToInt32(dr["DepartmentId"]);
            }

            _IsLoading = false;
        }
        public override void Show_Form()
        {
            this.ShowDialog();
        }


        private void btnSave_Click(object sender, EventArgs e)
        {
            tbl_Department_Info i = new tbl_Department_Info();
            FormGlobals.Panel_GetData(this, i);
            i.DepartmentId = _DepartmentId;
            i.CreateUser = FormGlobals.strUserName;
            i.LastUser = FormGlobals.strUserName;

            txtDepartmentCode.BackColor = SystemColors.Window;
            if (tbl_Department_Controller.Instance().IsExist(i))
            {
                txtDepartmentCode.BackColor = Color.Yellow;
                FormGlobals.Message_Warning(lblDepartmentCode.Text + UIMessage.EXIST);
                txtDepartmentCode.Focus();
                return;
            }

            _DepartmentId = tbl_Department_Controller.Instance().Save(i);
            if (_DepartmentId > 0)
            {
                FormGlobals.Message_InTaskbar(UIMessage.SAVE_COMPLETE);
                _dlgResult = DialogResult.OK;
                this.Close();
            }
        }
    }
}
